/*
----------------------------------------------------------------------------------------------------
This source file is part of the Gamut Framework
Copyright (c) 2007 by Ryan Holcombe

This program is free software; you can redistribute it and/or modify it under the terms of the GNU
Lesser General Public License as published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
----------------------------------------------------------------------------------------------------
*/


#ifndef _LogFile_h_
#define _LogFile_h_

#include "GamutILogListener.h"
#include <string>
#include <fstream>

namespace Gamut
{

	/**
 		Logs events to a file in XML format, seperated based on whatever
		namespace is passed in.

		\remarks
			Object is a listener which must be attached to the main Logger
	*/

	class LogFile : public ILogListener
	{
	private:
		//! local name of file to open
		std::string mLogFile;
		
		//! log directory to store file in
		std::string mLogDir;

		//! log name
		std::string mLogName;
		
		//! xsl file to generate
		std::string mXslFile;

		//! file stream to output log to
		std::ofstream mFile;
		
		//! tracks number of entries
		int mEntryCnt;
		
		/**
			\brief create the xsl style sheet and store it in the log directory
			\remarks does not overwrite the xsl file if it already exists
		*/
		virtual void generateXSL() const;
				
	public:

		/** Default constructor
			\param[in] name log name to be displayed at the top of the log
 			\param[in] log name of the file to open (default is log.xml)
			\param[in] dir directory to the store the log file and xsl stylesheet (default is log)
 		*/
		LogFile(const std::string& name = "Game Log", const std::string& log = "log.xml", const std::string& dir = "log");


		/**
 			\brief prepares the log for accepting entries [virtual]
			\remarks
				open the file for writing, write the xml headers (date and time),
				and generate the xsl stylesheet
		*/
		virtual void onListenerAdd();
		
		
		/**
			\brief close the file and cleans up all variables [virtual]
		*/
		virtual void onListenerDestroy();
		
		
		/**
			\brief writes an entry to the file [virtual]
		*/		
		virtual void writeEntry(const std::string& msg, const std::string& file, int line,
								const std::string& time, const std::string& level);
	};
}


#endif
